/*******************************************************************************
*  file    :
*  created : 25.11.2014
*  author  : Slyshyk Oleksiy (alexSlyshyk@gmail.com)
*******************************************************************************/

#ifndef QLOGGERCOLORCONSOLEAPPENDER_HPP
#define QLOGGERCOLORCONSOLEAPPENDER_HPP


#include "qloggerconf.hpp"
#include "qloggerconsoleappender.hpp"
#include "qloggerevent.hpp"
#include <QSharedPointer>
#include <QMap>

#ifdef _WIN32
    #include <conio.h>
    #include <qt_windows.h>
#else
    #include <termios.h>
    #include <unistd.h>
    #include <fcntl.h>
#endif

class QLOGGER_DECL QLoggerColorConsoleAppender : public QLoggerConsoleAppender
{
public:
    QLoggerColorConsoleAppender(int level, FILE *stream,
                                const QString &format,
                                const QString& time_format = "yyyy.MM.dd hh:mm:ss.zzz");
    ~QLoggerColorConsoleAppender();

    void write (const QLoggerEvent &event);
    void setLevelColor(QLoggerLevel lvl, short color);

private:
    void setColor();
    void setFGColor(const short color);
    void initColors();
private:
#ifdef _WIN32
    int BGColor;
    int FGColor;
    HANDLE hConsole;
#else
    std::string BGColor;
    std::string FGColor;
#endif
    QMap<int,int> levelColors_;
};

#endif // QLOGGERCOLORCONSOLEAPPENDER_HPP
